package com.lufei4.chestnut.view;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lufei4.chestnut.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ProjectName: Chestnut
 * @Package: com.lufei4.chestnut.view
 * @ClassName: MainListActivity
 * @Description: java类作用描述
 * @Author: liushijiang 15833013864@163.com
 * @CreateDate: 2020/12/25 11:23
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/12/25 11:23
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class MainListActivity extends AppCompatActivity {
    @BindView(R.id.mEditText)
    EditText mEditText;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    private List<String> list;
    private AdapterMainList mAdapterMainList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        ButterKnife.bind(this);
        initData();
        initView();
        setmRecyclerView();
    }

    private void setmRecyclerView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapterMainList = new AdapterMainList(new ArrayList<>());
        mRecyclerView.setAdapter(mAdapterMainList);
        mAdapterMainList.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String s = (String) adapter.getData().get(position);
                Toast.makeText(MainListActivity.this, s, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        mEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                Log.d("lufei_text_aaaa", s.toString() + "___number:" + count);
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Log.d("lufei_text_bbbb", s.toString() + "___number:" + count);
                mAdapterMainList.setNewData( searchList(s.toString()));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    private List<String> searchList(String aaa) {
        List<String> 结果列表 = new ArrayList<>();
        for (String s : list) {
            if (s.contains(aaa)) {
                结果列表.add(s);
            }
        }
        return 结果列表;
    }

    private void initData() {
        list = new ArrayList<>();
        list.add("打字机商店—销售、服务和出租");
        list.add("燃料经销商－燃油、木材、煤炭和液化石油");
        list.add("宠物商店、宠物食品及用品");
        list.add("游泳池－销售、供应和服务");
        list.add("电动剃须刀商店－销售和服务");
        list.add("其他专门零售店");
        list.add("不动产管理－物业管理");
        list.add("洗衣店");
        list.add("洗熨服务（自助洗衣服务）");
        list.add("干洗店");
        list.add("修鞋店、擦鞋店、帽子清洗店");
        list.add("税收准备服务");
        list.add("购物服务及会所（贸易、经纪服务）");
        list.add("复印及绘图服务");
        list.add("灭虫及消毒服务");
        list.add("职业中介、临时工");
        list.add("信息检索服务");
        list.add("未列入其他代码的计算机维护和修理服务");
        list.add("侦探、保安、安全服务");
        list.add("照相洗印服务");
        list.add("车体维修店");
        list.add("轮胎翻新、维修店");
        list.add("汽车喷漆店");
        list.add("电子游戏供给");
        list.add("手足病医生");

    }
}
